const path = require('path')
const myPlugin = require("./webpackPlugin.js")
module.exports = {
    //是否生成map文件
    productionSourceMap: false,
    chainWebpack: config => {
        const types = ['vue-modules', 'vue', 'normal-modules', 'normal']
        types.forEach(type => addStyleResource(config.module.rule('stylus').oneOf(type)))
        //去掉打包后的文件哈希值
        if (process.env.NODE_ENV === 'production') {
            config.output.filename('js/[name]-test.js').end()
            config.output.chunkFilename('js/[name].js').end()
            config.plugin('extract-css').tap(args => [{
                filename: `css/[name]-pc.css`,
                chunkFilename: `css/[name].css`
            }])
        }
    },

    configureWebpack: config => {
        if (process.env.NODE_ENV === 'production') {
            config.plugins.push(
                new myPlugin()
            )
        }
    }
}
//全局样式文件
function addStyleResource(rule) {
    rule.use('style-resource')
        .loader('style-resources-loader')
        .options({
            patterns: [
                path.resolve(__dirname, './src/common/stylus/root.styl')
            ],
        })
}
